package com.example.aoptestdemo.autoProxy;

import org.springframework.cglib.proxy.Callback;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class MyCallback implements MethodInterceptor {

    Object target;

    public MyCallback(Object target) {
        this.target = target;
    }

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {

        //增强

        //前置
        System.out.println("前置");

        //目标对象
        Object returnValue = proxy.invoke(target, args);

        //后置
        System.out.println("后置");
        return returnValue;
    }
}
